/**
 * @author Jason Tong
 * @date 2019/5/5 12:35.
 */

import java.sql.*;
public class MySQL2{
    public static void main(String [] args) {
        Connection con=null;
        Statement sql;
        ResultSet rs;
        String c1=" Region Like 'Middle East'";
        String sqlStr =
                "select * from country where "+c1;
        try{  Class.forName("com.mysql.cj.jdbc.Driver");
        }
        catch(Exception e){}
        String uri = "jdbc:mysql://localhost:3306/world?serverTimezone=GMT%2B8";
        String user ="root";
        String password ="";
        try{
            con = DriverManager.getConnection(uri,user,password);
        }
        catch(SQLException e){ }
        try {
            sql=con.createStatement();
            rs = sql.executeQuery(sqlStr);
            long totalPopulation=0;
            while(rs.next()) {
                int Population=rs.getInt(7);
                totalPopulation +=Population;
            }
            System.out.printf("中东总人口为"+totalPopulation);
            con.close();
        }
        catch(SQLException e) {
            System.out.println(e);
        }
    }
}


